package com.yc.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yc.entity.Record;
import com.yc.mapper.RecordMapper;
import com.yc.service.IRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * InnoDB free: 4096 kB 服务实现类
 * </p>
 *
 * @author zzw
 * @since 2022-06-18
 */
@Service
public class RecordServiceImpl extends ServiceImpl<RecordMapper, Record> implements IRecordService {
    @Resource
    private RecordMapper recordMapper;

    @Override
    public Integer addRecord(Integer uid, Integer ctid, Integer pid) {
        Record record=new Record();
        record.setUid(uid);
        record.setCtid(ctid);
        record.setPid(pid);
        record.setRcdate(LocalDateTime.now());
        return recordMapper.insert(record);
    }

    @Override
    public Integer updateRecord(Record record,Integer pid) {
        System.out.println(record.toString()+"  pid:"+pid);
        UpdateWrapper updateWrapper=new UpdateWrapper();
        updateWrapper.set("pid",pid);
        updateWrapper.set("rcdate",LocalDateTime.now());
        updateWrapper.eq("rcid",record.getRcid());
        return recordMapper.update(record,updateWrapper);
    }

    @Override
    public Integer deleteByRcidList(List< Integer > rcidlist) {
        QueryWrapper queryWrapper=new QueryWrapper();
        queryWrapper.in("rcid",rcidlist);
        return recordMapper.delete(queryWrapper);
    }
}
